﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Dreamz
{
    public class Rum0
    {
        static public void Apply()
        {
           // Here, the events followed on using/taking the key, the corpse and the candles are invoked.
            GameEngine.S.World[3, 0].Items["key"].OnUse += new EventHandler(UnlockDoor);
            GameEngine.S.World[3, 0].Items["candles"].OnTake += new EventHandler(TakeCandles);
            GameEngine.S.World[3, 0].Items["corpse"].OnTake += new EventHandler(TakeCorpse);
        }

        static public void TakeCorpse()
        {
           // This gives the sad news that your character have died, and resets the game.
            UI.Console.Clear();
            UI.Console.Write("[GAME OVER]", ConsoleColor.Red);
            UI.Console.WriteLine(@"The corpse did not die trying to escape, it was infected by HIV, Anthrax and The Bird Flu.
As you pick it up, you get all of these diseases. Why would you want to pick a corpse up anyway?");
            UI.Draw();
            Console.ReadKey();
            Console.Clear();
            GameEngine.S.Menu();
        }
        static public void TakeCandles()
        {
           // This method changes the descriptions mentioning candles, and add an usage eventhandler to the candles. (A method invoked while using the 'use' command.
            GameEngine.S.World[3, 0].Description = "You enter a cell with a rotten corpse on the ground.\n";
            GameEngine.S.Player.Inventory["candles"].OnUse += new EventHandler(UseCandles);
            GameEngine.S.World[3, 0].FirstDescription = @"You see a bench made out of stone, where you unsuccesfully tried to sleep.
The bench fortunately has a couple of cushions, unfortunately they are made of stone as well.
The door to your right looks like it's meant to stay closed, at least your newly diseased cellmate 
didn't seem to be able to break through. 
The corpse's hands have been mutilated trying to claw through to freedom.
At least you get to sleep alone, undisturbed.";
        }
        static public void UseCandles()
        {
            // This method is invoked when the player 'uses' the candles. It checks if the player is in the final room of the game, asks them what they want to use the candles.
            // If they chose to use it on the dynamite, the game ends.
            if (GameEngine.S.Player.X == 4 && GameEngine.S.Player.Y == 5)
            {
                Console.Clear();
                string answer;
                UI.Console.Write("What do you want to use the lit candles on?\n");
                UI.Draw();
                answer = Console.ReadLine().ToLower();
                if (answer == "explosives" || answer == "dynamite" || answer == "fuse")
                {
                    UI.Console.Clear();
                    UI.Console.Write("CONGRATULATIONS, YOU WON THE GAME!", ConsoleColor.Green);
                    UI.Console.WriteLine("As you put the candle to the sticks of dynamite, you realize that it was a pretty stupid thing to do.\nThe Flame crept slowly down, engulfing the explosive material. Just as you are about to get blown into\nsmall pieces, you get blown into small pieces. As your body is blown to oblivion, you are chocked \nby the fact that you are still able to think. Something within you lives on, but you do not know where you are.\nIs it a dream? Is it the afterlife? Are you actually waking up?\nThis we'll never know, but I'm sure you'll live happy ever after.\nOr not.\n\nThe end.\n");
                    UI.Draw();
                    Console.ReadKey();
                    System.Environment.Exit(1);
                }
            }
            else
            {
                UI.Console.Write("Stop this gibberish!");
            }
        }
        static public void UnlockDoor()
        {
            GameEngine.S.World[3, 0].North = !GameEngine.S.World[3, 0].North;
            // Code to open/close the door in the room where you start
            if (GameEngine.S.World[3, 0].North == true)
            {
                UI.Console.Write("You unlocked the door, you may now go to the [north]");
            }
            else
            {
                UI.Console.Write("You locked the door, you fool!");
            }
        }
    } 
}
